#include "widget.h"
#include "ui_widget.h"
#include<QPixmap>
#include"mylabelclass.h"
#include<QPushButton>
#include<QDebug>
#include<QPaintEvent>
#include<QMessageBox>
#include<QTimer>
#include"mypushbutton.h"
#include"operationwindow.h"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPixmap pix;

    setWindowTitle("高密度电阻率测量系统接线");
    pix.load(":/res1.jpg");
    myLabelClass *label = new myLabelClass;
    label->setParent(this);
    label->setPixmap(pix);
    label->setGeometry(0,0,982,574);
    this->setFixedSize(982,574);
//    this->setGeometry(200,100,982,574);
    label->show();

    //创建一个撤销按钮
    myPushButton * btnBack = new myPushButton(this);
    btnBack->setParent(this);
    btnBack->setGeometry(700,500,60,40);
    //创建一个清空按钮
    myPushButton * btnClear = new myPushButton(this);
    btnClear->setGeometry(800,500,60,40);
    //创建一个确定按钮
    myPushButton * btnOK = new myPushButton(this);
    btnOK->setGeometry(900,500,60,40);
    //创建下一步按钮，并先隐藏起来
    myPushButton *btnNext = new myPushButton(this);
    btnNext->setGeometry(400,500,200,40);
    btnNext->setText("进入仪器操作界面");
    btnNext->hide();

//    //设置按钮样式
//    setStyleSheet(
//                "QPushButton{"
//                "background-color:rgba(0,245,255);"//背景色（也可以设置图片）
//                "border-style:outset;"                  //边框样式（inset/outset）
//                "border-width:4px;"                     //边框宽度像素
//                "border-radius:10px;"                   //边框圆角半径像素
//                "border-color:rgba(10,255,255,30);"    //边框颜色
//                "font:bold 15px;"                       //字体，字体大小
//                "color:rgba(0,0,0,100);"                //字体颜色
//                "padding:6px;"                          //填衬
//                "}"
//                //鼠标按下样式
//                "QPushButton:pressed{"
//                "background-color:rgba(100,255,100,200);"
//                "border-color:rgba(255,255,255,30);"
//                "border-style:inset;"
//                "color:rgba(0,0,0,100);"
//                "}"
//                //鼠标悬停样式
//                "QPushButton:hover{"
//                "background-color:rgba(100,255,100,100);"
//                "border-color:rgba(255,255,255,200);"
//                "color:rgba(0,0,0,200);"
//                "}");
    btnBack->setText("撤销");
    btnOK->setText("确定");
    btnClear->setText("清空");
    //    btnBack->show();
    //点击撤销
    connect(btnBack,&QPushButton::clicked,[=](){
        if(~label->lines.isEmpty())
            {
            label->lines.removeLast();
            //        qDebug()<<label->lines;
            //        label->paintEvent(QPaintEvent *event);
            update();
        }
    });
    //点击清空
    connect(btnClear,&QPushButton::clicked,[=](){
        if(~label->lines.isEmpty())
            {
            label->lines.clear();
            //        qDebug()<<label->lines;
            //        label->paintEvent(QPaintEvent *event);
            update();
        }
    });
        //点击确定后，打开新界面显示正确接线
    connect(btnOK,&QPushButton::clicked,[=](){
        if(QMessageBox::Yes == QMessageBox::question(this,"提问","是否确定完成接线操作",QMessageBox::Yes|QMessageBox::No))
        {
//            qDebug()<<"yes";
            windowChange();
//            QMessageBox::question(this,"提示","请确认连线是否正确");
            btnNext->show();
        }
    });

    //点击进入下一步，到达仪器操作界面
    connect(btnNext,&myPushButton::clicked,[=](){

        this->hide();
        operation.show();

    });

     QObject::connect(&operation,SIGNAL(toMainWindow()),this,SLOT(tomainSlot()));

     //设置一个弹出式窗口进行提示
     QTimer *timer = new QTimer(this);
     timer->start(500);
     connect(timer,&QTimer::timeout,[=](){
         QMessageBox::information(this,"提示","请使用鼠标完成正确的仪器接线方式");
         timer->stop();
     });

}

void Widget::windowChange()
{
    subWindow.show();
}
void Widget::tomainSlot()
{
    this->show();
    operation.hide();
}

Widget::~Widget()
{
    delete ui;
}

